import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

export default defineConfig({
  plugins: [
    uni({
      vueOptions: {
        reactivityTransform: true
      }
    })
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          // 微信小程序兼容性变量
          $weapp-compatible: true;
        `
      }
    },
    postcss: {
      plugins: [
        {
          postcssPlugin: 'weapp-compatible',
          Declaration(decl) {
            // 替换不兼容的CSS属性
            if (decl.prop === 'gap') {
              decl.remove()
            }
            if (decl.value && decl.value.includes('vh')) {
              decl.value = decl.value.replace(/(\d+)vh/g, (match, num) => {
                return `${parseInt(num) * 13.34}rpx`
              })
            }
          }
        }
      ]
    }
  },
  build: {
    target: 'es2015',
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  }
})